﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;

namespace TRIG_MOD_STATUSSUMMARY.IRs_StatusSummary
{
    public partial class IRs_StatusSummaryUserControl : UserControl
    {
        DataForStatusSummary objCls = new DataForStatusSummary();
        List<string> docTypes = new List<string>();
        List<string> discipAbb = new List<string>();

        public List<string> DocTypes
        {
            get { return docTypes; }
            set { docTypes = value; }
        }

        public List<string> Disciplines
        {
            get { return discipAbb; }
            set { discipAbb = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            stDT.MaxDate = DateTime.Today;
            endDT.MaxDate = DateTime.Today;
            stSumGrid.DataSource = null;
            stSumGrid.Visible = false;
            if (Convert.ToInt32(rdDates.SelectedItem.Value) == 0)
            {
                stDT.SelectedDate = DateTime.Today;
                endDT.Visible = false;
                stDT.IsRequiredField = true; 
            }
            else
            {
                endDT.Visible = true;
                stDT.IsRequiredField = true;
                endDT.IsRequiredField = true;
            }
        }

        protected void rdDates_SelectedIndexChanged2(object sender, EventArgs e)
        {
            stDT.ClearSelection();
            endDT.ClearSelection();
            stSumGrid.DataSource = null;
            stSumGrid.Visible = false;

        }

        //protected void btnProcess_Click1(object sender, EventArgs e)
        //{

        //    NullLabels();

        //    objCls.rdDates = rdDates;
        //    if (Convert.ToInt32(rdDates.SelectedItem.Value) == 1) // As of Today
        //        GetDates();
        //    else
        //        GetDates("Today");
        //    objCls.grid = stSumGrid;

        //    string Type = "CNT";
        //    if (Type == "CNT")
        //    { objCls.CreateTable("IR_CNT"); objCls.Group = ("CNT"); }
        //    else { objCls.CreateTable("IR_CNS"); objCls.Group = ("CNS"); }

        //    int ckData = objCls.GetDocItemsbyDiscipiline("Inspection Requests", errorMessage, "IR");
        //    if (ckData > 0)
        //        objCls.BindGrid(stSumGrid, "IR");
        //    else { }
        //}

        private void NullLabels()
        {
            errorMessage.Text = "";
            stSumGrid.Visible = true;
        }

        private void GetDates(string today)
        {
            string startDt = Convert.ToString(stDT.SelectedDate.ToShortDateString());
            objCls.cpStDT = startDt;
            objCls.cpEndDT = startDt;

        }

        private void GetDates()
        {
            //stDT.IsRequiredField = true;
            //endDT.IsRequiredField = true;
            string startDt = Convert.ToString(stDT.SelectedDate.ToShortDateString());
            string endDt = Convert.ToString(endDT.SelectedDate.ToShortDateString());
            objCls.cpStDT = startDt;
            objCls.cpEndDT = endDt;

        }

        protected void btnProcessIR_Click(object sender, EventArgs e)
        {
            NullLabels();

            objCls.rdDates = rdDates;
            if (Convert.ToInt32(rdDates.SelectedItem.Value) == 1) // As of Today
                GetDates();
            else
                GetDates("Today");
            objCls.grid = stSumGrid;

            string Type = "CNT";
            if (Type == "CNT")
            { objCls.CreateTable("IR_CNT"); objCls.Group = ("CNT"); }
            else { objCls.CreateTable("IR_CNS"); objCls.Group = ("CNS"); }

            int ckData = objCls.GetDocItemsbyDiscipiline("Inspection Requests", errorMessage, "IR");
            if (ckData > 0)
                objCls.BindGrid(stSumGrid, "IR");
            else { }
        }

    }
}
